package icu.qx.sys.service.impl;

import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDictType;
import icu.qx.sys.domain.SysCode;
import icu.qx.sys.mapper.SysCodeMapper;
import icu.qx.sys.param.SysCodeParam;
import icu.qx.sys.service.SysCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCodeServiceImpl implements SysCodeService {

    @Autowired
    private SysCodeMapper sysCodeMapper;

    /**
     * 通过条件查询所有的系统编码
     */
    @Override
    public List<SysCode> selectSysCodeList(SysCodeParam sysCodeParam) {
        return sysCodeMapper.selectSysCodeList(sysCodeParam);
    }

    /**
     * 判断是否有重复的 展示名称
     */
    @Override
    public Boolean checkShowNameUnique(SysCode sysCode) {
        String codeShowName = sysCode.getCodeShowName();
        SysCode sysShowName = sysCodeMapper.checkShowNameUnique(sysCode.getCodeShowName());
        if (StringUtils.isNotNull(sysShowName) && !sysShowName.getCodeShowName().equals(codeShowName)) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 通过id主键查询详细信息
     */
    @Override
    public SysCode selectSysCodeById(Long codeId) {
        return sysCodeMapper.selectSysCodeById(codeId);
    }

    /**
     * 通过关联表单查询详细信息
     */
    @Override
    public SysCode selectSysCodeByCodeTableName(String codeTableName) {
        return sysCodeMapper.selectSysCodeByCodeTableName(codeTableName);
    }

    /**
     * 添加系统编码
     */
    @Override
    public Integer insertSysCode(SysCode sysCode) {
        sysCode.setCreateBy(SecurityUtils.getUsername());
        return sysCodeMapper.insertSysCode(sysCode);
    }

    /**
     * 修改系统编码
     */
    @Override
    public Integer updateSysCode(SysCode sysCode) {
        sysCode.setUpdateBy(SecurityUtils.getUsername());
        return sysCodeMapper.updateSysCode(sysCode);
    }
}
